home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
Views
/
Tiled Views
/
RuledFourSquareTiling.cp
< prev
next >
Wrap
Text File
|
2000-06-23
|
8KB
|
239 lines
// RuledFourSquareTiling.cp
#ifndef RuledFourSquareTiling_h
#include "RuledFourSquareTiling.h"
#endif
#ifndef MinMax_h
#include "MinMax.h"
#endif
#ifndef ViewCell_h
#include "ViewCell.h"
#endif
RuledFourSquareTiling::RuledFourSquareTiling()
{
Add( topLeft, afterEnd );
Add( topRight, afterEnd );
Add( bottomLeft, afterEnd );
Add( bottomRight, afterEnd );
Add( horizontalLine, afterEnd );
Add( upperVerticalLine, afterEnd );
Add( lowerVerticalLine, afterEnd );
horizontalLine.SetContent( ViewCell::Black() );
upperVerticalLine.SetContent( ViewCell::Black() );
lowerVerticalLine.SetContent( ViewCell::Black() );
}
int32 RuledFourSquareTiling::TileSum( int32 a, int32 b )
{
return ( a < maxint32 - 1 - b )
? a + 1 + b
: maxint32;
}
int32 RuledFourSquareTiling::HorizontalSplitPosition() const
{
int32 minimumLeft = Max( topLeft.Sizer().MinimumWidth(),
bottomLeft.Sizer().MinimumWidth() );
if ( minimumLeft >= PaneSize().h )
return PaneSize().h;
int32 minimumRight = Max( topRight.Sizer().MinimumWidth(),
bottomRight.Sizer().MinimumWidth() );
if ( minimumRight >= PaneSize().h - 1 - minimumLeft )
return minimumLeft;
int32 maximumRight = Min( topRight.Sizer().MaximumWidth(),
bottomRight.Sizer().MaximumWidth() );
Range32 leftRange( Max( 1ul, PaneSize().h - 1 - maximumRight ),
PaneSize().h - 1 - minimumRight );
return Max( topLeft.Sizer().BestWidth( leftRange ),
bottomLeft.Sizer().BestWidth( leftRange ) );
}
int32 RuledFourSquareTiling::VerticalSplitPosition() const
{
int32 minimumTop = Max( topLeft.Sizer().MinimumHeight(),
topRight.Sizer().MinimumHeight() );
if ( minimumTop >= PaneSize().v )
return PaneSize().v;
int32 minimumBottom = Max( bottomLeft.Sizer().MinimumHeight(),
bottomRight.Sizer().MinimumHeight() );
if ( minimumBottom >= PaneSize().v - 1 - minimumTop )
return minimumTop;
int32 maximumBottom = Min( bottomLeft.Sizer().MaximumHeight(),
bottomRight.Sizer().MaximumHeight() );
Range32 topRange( Max( 1ul, PaneSize().v - 1 - maximumBottom ),
PaneSize().v - 1 - minimumBottom );
return Max( topLeft.Sizer().BestHeight( topRange ),
topRight.Sizer().BestHeight( topRange ) );
}
void RuledFourSquareTiling::PaneSizeChanged()
{
Point32 oldSize = bottomRight.Bounds().BottomRight();
Rectangle32 keyPixel;
keyPixel.left = HorizontalSplitPosition();
keyPixel.top = VerticalSplitPosition();
keyPixel.right = Min( keyPixel.left + 1ul, PaneSize().h );
keyPixel.bottom = Min( keyPixel.top + 1ul, PaneSize().v );
topLeft.proposedBounds = Rectangle32( 0, 0,
keyPixel.left, keyPixel.top );
topRight.proposedBounds = Rectangle32( keyPixel.right, 0,
PaneSize().h, keyPixel.top );
bottomLeft.proposedBounds = Rectangle32( 0, keyPixel.bottom,
keyPixel.left, PaneSize().v );
bottomRight.proposedBounds = Rectangle32( keyPixel.right, keyPixel.bottom,
PaneSize().h, PaneSize().v );
horizontalLine.proposedBounds = Rectangle32( 0, keyPixel.top,
PaneSize().h, keyPixel.bottom );
upperVerticalLine.proposedBounds = Rectangle32( keyPixel.left, 0,
keyPixel.right, keyPixel.top );
lowerVerticalLine.proposedBounds = Rectangle32( keyPixel.left, keyPixel.bottom,
keyPixel.right, PaneSize().v );
TiledPane *shuffleFirst = 0;
if ( PaneSize().h < oldSize.h )
if ( PaneSize().v < oldSize.v )
{
shuffleFirst = &topLeft;
topLeft .shuffleNext = &upperVerticalLine;
upperVerticalLine .shuffleNext = &topRight;
topRight .shuffleNext = &horizontalLine;
horizontalLine .shuffleNext = &bottomLeft;
bottomLeft .shuffleNext = &lowerVerticalLine;
lowerVerticalLine .shuffleNext = &bottomRight;
bottomRight .shuffleNext = 0;
}
else
{
shuffleFirst = &bottomLeft;
bottomLeft .shuffleNext = &lowerVerticalLine;
lowerVerticalLine .shuffleNext = &bottomRight;
bottomRight .shuffleNext = &horizontalLine;
horizontalLine .shuffleNext = &topLeft;
topLeft .shuffleNext = &upperVerticalLine;
upperVerticalLine .shuffleNext = &topRight;
topRight .shuffleNext = 0;
}
else
if ( PaneSize().v < oldSize.v )
{
shuffleFirst = &topRight;
topRight .shuffleNext = &upperVerticalLine;
upperVerticalLine .shuffleNext = &topLeft;
topLeft .shuffleNext = &horizontalLine;
horizontalLine .shuffleNext = &bottomRight;
bottomRight .shuffleNext = &lowerVerticalLine;
lowerVerticalLine .shuffleNext = &bottomLeft;
bottomLeft .shuffleNext = 0;
}
else
{
shuffleFirst = &bottomRight;
bottomRight .shuffleNext = &lowerVerticalLine;
lowerVerticalLine .shuffleNext = &bottomLeft;
bottomLeft .shuffleNext = &horizontalLine;
horizontalLine .shuffleNext = &topRight;
topRight .shuffleNext = &upperVerticalLine;
upperVerticalLine .shuffleNext = &topLeft;
topLeft .shuffleNext = 0;
}
ShufflePanes( shuffleFirst );
}
int32 RuledFourSquareTiling::MinimumWidth() const
{
return TileSum( Max( topLeft.Sizer().MinimumWidth(), bottomLeft.Sizer().MinimumWidth() ),
Max( topRight.Sizer().MinimumWidth(), bottomRight.Sizer().MinimumWidth() ) );
}
int32 RuledFourSquareTiling::MinimumHeight() const
{
return TileSum( Max( topLeft.Sizer().MinimumHeight(), topRight.Sizer().MinimumHeight() ),
Max( bottomLeft.Sizer().MinimumHeight(), bottomRight.Sizer().MinimumHeight() ) );
}
int32 RuledFourSquareTiling::MaximumWidth() const
{
return TileSum( Min( topLeft.Sizer().MaximumWidth(), bottomLeft.Sizer().MaximumWidth() ),
Min( topRight.Sizer().MaximumWidth(), bottomRight.Sizer().MaximumWidth() ) );
}
int32 RuledFourSquareTiling::MaximumHeight() const
{
return TileSum( Min( topLeft.Sizer().MaximumHeight(), topRight.Sizer().MaximumHeight() ),
Min( bottomLeft.Sizer().MaximumHeight(), bottomRight.Sizer().MaximumHeight() ) );
}
int32 RuledFourSquareTiling::ReasonableWidth() const
{
return TileSum( Max( topLeft.Sizer().ReasonableWidth(), bottomLeft.Sizer().ReasonableWidth() ),
Max( topRight.Sizer().ReasonableWidth(), bottomRight.Sizer().ReasonableWidth() ) );
}
int32 RuledFourSquareTiling::ReasonableHeight() const
{
return TileSum( Max( topLeft.Sizer().ReasonableHeight(), topRight.Sizer().ReasonableHeight() ),
Max( bottomLeft.Sizer().ReasonableHeight(), bottomRight.Sizer().ReasonableHeight() ) );
}
int32 RuledFourSquareTiling::BestWidth( Range32 bounds ) const
{
int32 minimumRight = TileSum( 0, Max( topRight.Sizer().MinimumWidth(), bottomRight.Sizer().MinimumWidth() ) );
if ( minimumRight >= bounds.End() )
return bounds.End();
Range32 leftBounds( Max( 0L, bounds.Start() - minimumRight ), bounds.End() - minimumRight );
int32 left = TileSum( Max( topLeft.Sizer().BestWidth( leftBounds ), bottomLeft.Sizer().BestWidth( leftBounds ) ), 0 );
if ( left >= bounds.End() - minimumRight )
return bounds.End();
Range32 rightBounds( Max( 0L, bounds.Start() - left ), bounds.End() - left );
return left + Max( topRight.Sizer().BestWidth( rightBounds ), bottomRight.Sizer().BestWidth( rightBounds ) );
}
int32 RuledFourSquareTiling::BestHeight( Range32 bounds ) const
{
int32 minimumBottom = TileSum( 0, Max( bottomLeft.Sizer().MinimumHeight(), bottomRight.Sizer().MinimumHeight() ) );
if ( minimumBottom >= bounds.End() )
return bounds.End();
Range32 topBounds( Max( 0L, bounds.Start() - minimumBottom ), bounds.End() - minimumBottom );
int32 top = TileSum( Max( topLeft.Sizer().BestHeight( topBounds ), topRight.Sizer().BestHeight( topBounds ) ), 0 );
if ( top >= bounds.End() - minimumBottom )
return bounds.End();
Range32 bottomBounds( Max( 0L, bounds.Start() - top ), bounds.End() - top );
return top + Max( bottomLeft.Sizer().BestHeight( bottomBounds ), bottomRight.Sizer().BestHeight( bottomBounds ) );
}